package com.bole.controller;


import com.bole.data.Result;
import com.bole.data.ResultEnum;
import com.bole.dto.user.UserDto;
import com.bole.feign.UserFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("user")
@Api(value="会员管理接口")
public class UserController {

    @Autowired
    private UserFeign  userFeign;


    @GetMapping("tolist")
    @ApiOperation(value = "跳转会员页面")
    public String tolist(){
        return "user-list";
    }

    @PostMapping("getUserInfo")
    @ApiOperation(value = "查询会员信息")
    @ResponseBody
    public Result getContentCateInfo(){
        List<UserDto> list =  userFeign.getUserInfo();
        return Result.response(ResultEnum.OK).setData(list);
    }


    @PostMapping("toUpdate/{id}")
    @ApiOperation(value = "回显")
    @ApiImplicitParam(name = "id",value = "会员id",required = true,dataTypeClass = Long.class)
    @ResponseBody
    public Result toUpdate(@PathVariable("id")Long id){
        UserDto userDto = userFeign.toUpdate(id);
        return Result.response(ResultEnum.OK).setData(userDto);
    }


    @PostMapping("updateUserInfo")
    @ApiOperation(value = "修改会员信息")
    @ApiImplicitParam(name = "userDto",value = "会员对象",required = true,dataTypeClass = UserDto.class)
    @ResponseBody
    public Result updateUserInfo(@RequestBody UserDto userDto){
        userFeign.updateUserInfo(userDto);
        return Result.response(ResultEnum.OK);
    }


}
